package com.platform.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.platform.dao.ApiWxFromidMapper;
import com.platform.entity.WxFromidVo;

/**
 * Service实现类
 *
 * @author czj
 * @email 729618941@qq.com
 * @date 2018-10-16 14:31:18
 */
@Service
public class ApiWxFromidService {
    @Autowired
    private ApiWxFromidMapper wxFromidDao;


    public WxFromidVo queryObject(Integer id) {
        return wxFromidDao.queryObject(id);
    }


    public List<WxFromidVo> queryList(Map<String, Object> map) {
        return wxFromidDao.queryList(map);
    }


    public int queryTotal(Map<String, Object> map) {
        return wxFromidDao.queryTotal(map);
    }


    public int save(WxFromidVo wxFromid) {
        return wxFromidDao.save(wxFromid);
    }


    public int update(WxFromidVo wxFromid) {
        return wxFromidDao.update(wxFromid);
    }


    public int delete(Integer id) {
        return wxFromidDao.delete(id);
    }


    public int deleteBatch(Integer[] ids) {
        return wxFromidDao.deleteBatch(ids);
    }

    //清理过期、无效和已使用的fromid
    public void deleteTimeOutFromid() {
        wxFromidDao.deleteTimeOutFromid();
    }

    //找一个有效的Fromid
    public WxFromidVo getUsefulOne(String openid) {
        Map<String, Object> map = new HashMap<>();
        map.put("openid", openid);
        map.put("is_used", 0);
        map.put("sidx", "add_time");
        map.put("order", "asc");
        List<WxFromidVo> wxFromidVos = wxFromidDao.queryList(map);
        if (wxFromidVos.size() == 0) {
            return null;
        }
        return wxFromidVos.get(0);
    }

}
